current_debug = 1

def getDebugFlag():
    global current_debug
    ret = current_debug
    current_debug *= 2
    return ret

DEBUG_ULTIMATE=getDebugFlag()

DEBUG_LEVEL = DEBUG_ULTIMATE

def addLevel(level):
    global DEBUG_LEVEL
    if(DEBUG_LEVEL & level):
        return
    DEBUG_LEVEL = DEBUG_LEVEL + level
    return

def removeLevel(level):
    global DEBUG_LEVEL
    if(DEBUG_LEVEL & level):
        DEBUG_LEVEL = DEBUG_LEVEL - level
    return

def hasLevel(level):
    return (DEBUG_LEVEL & level) != 0

def debug(level, text):
    if hasLevel(level):
        print text
    return